package com.defangit.production.orm;

import com.defangit.production.bll.ProcessBll;
import com.defangit.production.bll.ProcessTimeBll;
import com.defangit.production.domain.ProcessTime;
import laogen.hibernate.CommonFinder;
import laogen.hibernate.CommonService;
import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

public class ProcessTimeService extends CommonService<ProcessTime> implements ProcessTimeBll {
    @Override
    public ProcessTime addTime(ProcessTime processTime) {
        return null;
    }

    @Override
    public ProcessTime updateTime(ProcessTime processTime) {
        return null;
    }

    @Override
    public ProcessTimeFinder findAll() {
        return new ProcessTimeFinderImp();
    }

    public class ProcessTimeFinderImp extends CommonFinder<ProcessTime> implements ProcessTimeFinder {

        private DetachedCriteria timeCriteria;
        private ProcessTimeFinderImp() {
            this.timeCriteria = detachedAll();
        }

        @Override
        public Criteria getCriteria() {
            return this.timeCriteria.getExecutableCriteria(getSession()).addOrder(Order.desc("id"));
        }

        @Override
        public DetachedCriteria getDetachedCriteria() {
            return this.timeCriteria;
        }
    }
}
